import createAxios from '/@/utils/axios'
import { useAdminInfo } from '/@/stores/adminInfo'
import { adminUploadUrl } from '/@/api/common'

/**
 * 用户管理模块API
 */
export default {
    /**
     * 查询用户列表
     * @param params 查询参数
     */
    getUserList: (params: Record<string, any>) => {
        return createAxios(
            {
                url: '/api/Sys/User/QueryList',
                method: 'post',
                data: params
            },
            {
                showSuccessMessage: false
            }
        )
    },

    /**
     * 新增/编辑用户
     * @param data 用户数据
     */
    saveUser: (data: Record<string, any>) => {
        return createAxios(
            {
                url: '/api/Sys/User/SaveUser',
                method: 'post',
                data
            },
            {
                showSuccessMessage: true
            }
        )
    },

    /**
     * 删除用户
     * @param id 用户ID
     */
    deleteUser: (id: number) => {
        return createAxios(
            {
                url: '/api/Sys/User/DelUser',
                method: 'post',
                data: {
                    id
                }
            },
            {
                showSuccessMessage: true
            }
        )
    },

    /**
     * 启用/禁用用户
     * @param id 用户ID
     * @param isEnable 是否启用
     */
    enableUser: (id: number, isEnable: boolean) => {
        return createAxios(
            {
                url: '/api/Sys/User/EnableUser',
                method: 'post',
                data: {
                    id,
                    isEnable
                }
            },
            {
                showSuccessMessage: true
            }
        )
    },

    /**
     * 批量删除用户
     * @param ids 用户ID数组
     */
    batchDeleteUsers: (ids: number[]) => {
        return createAxios(
            {
                url: '/api/Sys/User/DelUser',
                method: 'post',
                data: { ids }
            },
            {
                showSuccessMessage: true
            }
        )
    },

    /**
     * 批量启用/禁用用户
     * @param ids 用户ID数组
     * @param isEnable 是否启用
     */
    batchEnableUsers: (ids: number[], isEnable: boolean) => {
        return createAxios(
            {
                url: '/api/Sys/User/EnableUser',
                method: 'post',
                data: { ids, isEnable }
            },
            {
                showSuccessMessage: true
            }
        )
    },

    /**
     * 上传用户头像
     * @param file 头像文件
     */
    uploadAvatar: (file: File) => {
        const uploadData = new FormData()
        uploadData.append('file', file)

        return createAxios(
            {
                url: adminUploadUrl,
                method: 'post',
                data: uploadData,
                headers: { 'Content-Type': 'multipart/form-data' }
            }
        )
    }
}
